package com.asset.salesforce.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.asset.salesforce.dao.InvoiceDaoImpl;
import com.asset.salesforce.dao.InvoiceInvoiceTaxDaoImpl;
import com.asset.salesforce.dao.InvoiceItemDaoImpl;
import com.asset.salesforce.dao.InvoiceItemParentDaoImpl;
import com.asset.salesforce.dao.InvoiceServiceDaoImpl;
import com.asset.salesforce.dao.InvoiceSkuDaoImpl;
import com.asset.salesforce.domain.Invoice;
import com.asset.salesforce.domain.InvoiceItem;
import com.asset.salesforce.domain.InvoiceItemParent;
import com.asset.salesforce.domain.InvoiceService;
import com.asset.salesforce.domain.InvoiceSku;


@Service
@Transactional(readOnly=true)
public class InvoiceOperationService {
	
	@Autowired 
	InvoiceDaoImpl invoiceDaoImpl;
	
	@Autowired
	
	private InvoiceSkuDaoImpl invoiceSkuDaoImpl;
	
	@Autowired
	private InvoiceServiceDaoImpl invoiceServiceDaoImpl;
	
	@Autowired
	private InvoiceItemParentDaoImpl invoiceItemParentDaoImpl;
	
	@Autowired
	private InvoiceItemDaoImpl invoiceItemDaoImpl;

	@Autowired
	private InvoiceInvoiceTaxDaoImpl invoiceInvoiceTaxDaoImpl;
	
	@Transactional(readOnly=false)
	public void addInvoice(Invoice invoice) {
		 invoiceDaoImpl.add(invoice);
	}
	@Transactional(readOnly=true)
	public List<Invoice> getAllInvoicesByEmp(Integer id) {
		return invoiceDaoImpl.getInvoicesEmployeeId(id);
	}
	@Transactional(readOnly=true)
	public Invoice getInvoiceById(Integer id) {
		return invoiceDaoImpl.getById(id, new Invoice());
	}
	@Transactional(readOnly=false)
	public void addInvoiceParent(InvoiceItemParent invoiceItemParent) {
		invoiceItemParentDaoImpl.add(invoiceItemParent);
	}
	@Transactional(readOnly=false)
	public void addInvoiceSku(InvoiceSku invoiceSku) {
		invoiceItemParentDaoImpl.add((InvoiceItemParent)invoiceSku);
		invoiceSkuDaoImpl.add(invoiceSku);
	}
	@Transactional(readOnly=false)
	public void addInvoiceService(InvoiceService invoiceService) {
		invoiceItemParentDaoImpl.add((InvoiceItemParent)invoiceService);
		invoiceServiceDaoImpl.add(invoiceService);
	}
	@Transactional(readOnly=false)
	public void addInvoiceItem(InvoiceItem invoiceItem) {
		invoiceItemDaoImpl.add(invoiceItem);
	}
	@Transactional(readOnly=true)
	public List<InvoiceItem> getInvoiceItemsByInvoice(Integer id){
		return invoiceItemDaoImpl.getInvoiceItemsByInvoice(id);
	}
	@Transactional(readOnly=true)
	public List<InvoiceSku> getInvoiceSkusByInvoice(Integer id){
		return invoiceSkuDaoImpl.getInvoiceSkusByInvoice(id);
	}
	@Transactional(readOnly=true)
	public List<InvoiceService> getInvoiceServicesByInvoice(Integer id){
		return invoiceServiceDaoImpl.getInvoiceServicesByInvoice(id);
	}
	@Transactional(readOnly=true)
	public Invoice getInvoiceByEmployeeId(Integer empId) {
		return invoiceDaoImpl.getInvoiceByEmployeeId(empId);
	}
	@Transactional(readOnly=true)
	public Invoice getInvoice(Integer id){
		return invoiceDaoImpl.getInvoice(id);
	}
	@Transactional(readOnly=true)
	public List<String> getEachTaxSum(Integer id){
		return invoiceInvoiceTaxDaoImpl.getEachTaxSum(id);
	}
}
